/**
 *
 */
package org.tangram.component;

import java.util.List;

import org.tangram.util.ServiceLoader;

/**
 * 构件管理器接口
 * 
 * @author han_feng
 * 
 */
public abstract class ComponentManager {

	private static class DefaultComponentManagerHolder {

		static ComponentManager defaultComponentManager = load();

		private static ComponentManager load() {
			// 使用 ServiceLoader 从
			// META-INF/services/org.tangram.component.ComponentManager
			// 文件中获取接口实现
			ServiceLoader<ComponentManager> componentManagerLoader = ServiceLoader
					.load(ComponentManager.class);
			for (ComponentManager manager : componentManagerLoader) {
				if (manager != null) {
					return manager;
				}
			}
			throw new RuntimeException("Unable to load defaultComponentManager");
		}
	}

	public static ComponentManager getDefaultComponentManager() {
		// Bob Lee单例模式，参考网上案例
		return DefaultComponentManagerHolder.defaultComponentManager;
	}

	/**
	 * 获取全部构件，返回构件按照依赖关系排序，被依赖构件在前
	 * 
	 * @return
	 */
	public abstract List<Component> getAllComponent();

	/**
	 * 获取指定构件
	 * 
	 * @param groupId
	 * @param componentId
	 * @param version
	 * @return
	 */
	public abstract Component getComponent(String groupId, String componentId);

	/**
	 * 获取指定的扩展点定义
	 * 
	 * @param point
	 *            扩展点名称
	 * 
	 * @return
	 */
	public abstract ExtensionPoint getExtensionPoint(String point);

	/**
	 * 获取指定扩展点的所有扩展实现
	 * 
	 * @param point
	 *            扩展点名称
	 * @return
	 */
	public abstract List<Extension> getExtensions(String point);

}
